package com.example.demo;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TcpClientConfig {

    @Bean
    public EventLoopGroup eventLoopGroup() {
        return new NioEventLoopGroup();
    }

    @Bean
    public Bootstrap bootstrap(EventLoopGroup eventLoopGroup) {
        Bootstrap b = new Bootstrap();
        b.group(eventLoopGroup)
                .channel(NioSocketChannel.class)
                .handler(new TcpClientInitializer());
        return b;
    }

    @Bean
    public Channel channel(Bootstrap bootstrap) throws InterruptedException {
        Channel channel = bootstrap.connect("192.168.100.151", 65001).sync().channel();
        System.out.println("channel::::::::::::::::" + channel);
        return channel;
    }
}